<!DOCTYPE html>
<html lang="zh-cn">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <title>NSAttributedString - Coding Night - A personal blog for Rango</title>
  <meta name="renderer" content="webkit" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>

<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />

<meta name="theme-color" content="#f8f5ec" />
<meta name="msapplication-navbutton-color" content="#f8f5ec">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="#f8f5ec">


<meta name="author" content="Rango" /><meta name="description" content="字符属性 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15  /* 字符属性可以应用于 attributed string 的文本中。 NSString *const NSFontAttributeName;(字体) NSString *const NSParagraphStyleAttributeName;(段落) NSString *const NSForegroundColorAttributeName;(字体颜色) NSString *const NSBackgroundColorAttributeName;(字体背景色) NSString *const NSLigatureAttributeName;(连字符) NSString *const NSKernAttributeName;(字间距) NSString *const NSStrikethroughStyleAttributeName;(删除线) NSString *const NSUnderlineStyleAttributeName;(下划线) NSString *const NSStrokeColorAttributeName;(边线颜色) NSString *const NSStrokeWidthAttributeName;(边线宽度) NSString *const NSShadowAttributeName;(阴影)(横竖排版 NSString *const NSVerticalGlyphFormAttributeName;   " />






<meta name="generator" content="Hugo 0.97.3 with theme even" />


<link rel="canonical" href="https://rangolee.github.io/post/ios/16-0518_nsattributedstring/" />
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/manifest.json">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">



<link href="/sass/main.min.a659bb31b17a54f7792e1bc783fc75b31118e6a175b42337b03fae0b1a3ef2b5.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.1.20/dist/jquery.fancybox.min.css" integrity="sha256-7TyXnr2YU040zfSP+rEcz29ggW4j56/ujTPwjMzyqFY=" crossorigin="anonymous">


<meta property="og:title" content="NSAttributedString" />
<meta property="og:description" content="字符属性


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15


/*
 字符属性可以应用于 attributed string 的文本中。

 NSString *const NSFontAttributeName;(字体) 
 NSString *const NSParagraphStyleAttributeName;(段落) 
 NSString *const NSForegroundColorAttributeName;(字体颜色) 
 NSString *const NSBackgroundColorAttributeName;(字体背景色)
 NSString *const NSLigatureAttributeName;(连字符)
 NSString *const NSKernAttributeName;(字间距)
 NSString *const NSStrikethroughStyleAttributeName;(删除线)
 NSString *const NSUnderlineStyleAttributeName;(下划线)
 NSString *const NSStrokeColorAttributeName;(边线颜色)
 NSString *const NSStrokeWidthAttributeName;(边线宽度)
 NSString *const NSShadowAttributeName;(阴影)(横竖排版 
 NSString *const NSVerticalGlyphFormAttributeName;


" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://rangolee.github.io/post/ios/16-0518_nsattributedstring/" /><meta property="article:section" content="post" />
<meta property="article:published_time" content="2016-04-27T00:00:00+00:00" />
<meta property="article:modified_time" content="2016-04-27T00:00:00+00:00" />

<meta itemprop="name" content="NSAttributedString">
<meta itemprop="description" content="字符属性


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15


/*
 字符属性可以应用于 attributed string 的文本中。

 NSString *const NSFontAttributeName;(字体) 
 NSString *const NSParagraphStyleAttributeName;(段落) 
 NSString *const NSForegroundColorAttributeName;(字体颜色) 
 NSString *const NSBackgroundColorAttributeName;(字体背景色)
 NSString *const NSLigatureAttributeName;(连字符)
 NSString *const NSKernAttributeName;(字间距)
 NSString *const NSStrikethroughStyleAttributeName;(删除线)
 NSString *const NSUnderlineStyleAttributeName;(下划线)
 NSString *const NSStrokeColorAttributeName;(边线颜色)
 NSString *const NSStrokeWidthAttributeName;(边线宽度)
 NSString *const NSShadowAttributeName;(阴影)(横竖排版 
 NSString *const NSVerticalGlyphFormAttributeName;


"><meta itemprop="datePublished" content="2016-04-27T00:00:00+00:00" />
<meta itemprop="dateModified" content="2016-04-27T00:00:00+00:00" />
<meta itemprop="wordCount" content="1679">
<meta itemprop="keywords" content="OC,NSAttributedString," /><meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="NSAttributedString"/>
<meta name="twitter:description" content="字符属性


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15


/*
 字符属性可以应用于 attributed string 的文本中。

 NSString *const NSFontAttributeName;(字体) 
 NSString *const NSParagraphStyleAttributeName;(段落) 
 NSString *const NSForegroundColorAttributeName;(字体颜色) 
 NSString *const NSBackgroundColorAttributeName;(字体背景色)
 NSString *const NSLigatureAttributeName;(连字符)
 NSString *const NSKernAttributeName;(字间距)
 NSString *const NSStrikethroughStyleAttributeName;(删除线)
 NSString *const NSUnderlineStyleAttributeName;(下划线)
 NSString *const NSStrokeColorAttributeName;(边线颜色)
 NSString *const NSStrokeWidthAttributeName;(边线宽度)
 NSString *const NSShadowAttributeName;(阴影)(横竖排版 
 NSString *const NSVerticalGlyphFormAttributeName;


"/>

<!--[if lte IE 9]>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/classlist/1.1.20170427/classList.min.js"></script>
<![endif]-->

<!--[if lt IE 9]>
  <script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script>
<![endif]-->

</head>
<body>
  <div id="mobile-navbar" class="mobile-navbar">
  <div class="mobile-header-logo">
    <a href="/" class="logo">Coding Night</a>
  </div>
  <div class="mobile-navbar-icon">
    <span></span>
    <span></span>
    <span></span>
  </div>
</div>
<nav id="mobile-menu" class="mobile-menu slideout-menu">
  <ul class="mobile-menu-list">
    <a href="/">
        <li class="mobile-menu-item">Home</li>
      </a><a href="/post/">
        <li class="mobile-menu-item">Archives</li>
      </a><a href="/tags/">
        <li class="mobile-menu-item">Tags</li>
      </a><a href="/categories/">
        <li class="mobile-menu-item">Categories</li>
      </a><a href="/about/">
        <li class="mobile-menu-item">About</li>
      </a>
  </ul>

  


</nav>

  <div class="container" id="mobile-panel">
    <header id="header" class="header">
        <div class="logo-wrapper">
  <a href="/" class="logo">Coding Night</a>
</div>





<nav class="site-navbar">
  <ul id="menu" class="menu">
    <li class="menu-item">
        <a class="menu-item-link" href="/">Home</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/post/">Archives</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/tags/">Tags</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/categories/">Categories</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/about/">About</a>
      </li>
  </ul>
</nav>

    </header>

    <main id="main" class="main">
      <div class="content-wrapper">
        <div id="content" class="content">
          <article class="post">
    
    <header class="post-header">
      <h1 class="post-title">NSAttributedString</h1>

      <div class="post-meta">
        <span class="post-time"> 2016-04-27 </span>
        <div class="post-category">
            <a href="/categories/ios/"> iOS </a>
            </div>
          <span class="more-meta"> 约 1679 字 </span>
          <span class="more-meta"> 预计阅读 4 分钟 </span>
        
      </div>
    </header>

    <div class="post-toc" id="post-toc">
  <h2 class="post-toc-title">文章目录</h2>
  <div class="post-toc-content always-active">
    <nav id="TableOfContents">
  <ul>
    <li>
      <ul>
        <li>
          <ul>
            <li></li>
          </ul>
        </li>
      </ul>
    </li>
  </ul>
</nav>
  </div>
</div>
    <div class="post-content">
      <h4 id="字符属性">字符属性</h4>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-objective-c" data-lang="objective-c"><span class="line"><span class="cl"><span class="cm">/*
</span></span></span><span class="line"><span class="cl"><span class="cm"> 字符属性可以应用于 attributed string 的文本中。
</span></span></span><span class="line"><span class="cl"><span class="cm">
</span></span></span><span class="line"><span class="cl"><span class="cm"> NSString *const NSFontAttributeName;(字体) 
</span></span></span><span class="line"><span class="cl"><span class="cm"> NSString *const NSParagraphStyleAttributeName;(段落) 
</span></span></span><span class="line"><span class="cl"><span class="cm"> NSString *const NSForegroundColorAttributeName;(字体颜色) 
</span></span></span><span class="line"><span class="cl"><span class="cm"> NSString *const NSBackgroundColorAttributeName;(字体背景色)
</span></span></span><span class="line"><span class="cl"><span class="cm"> NSString *const NSLigatureAttributeName;(连字符)
</span></span></span><span class="line"><span class="cl"><span class="cm"> NSString *const NSKernAttributeName;(字间距)
</span></span></span><span class="line"><span class="cl"><span class="cm"> NSString *const NSStrikethroughStyleAttributeName;(删除线)
</span></span></span><span class="line"><span class="cl"><span class="cm"> NSString *const NSUnderlineStyleAttributeName;(下划线)
</span></span></span><span class="line"><span class="cl"><span class="cm"> NSString *const NSStrokeColorAttributeName;(边线颜色)
</span></span></span><span class="line"><span class="cl"><span class="cm"> NSString *const NSStrokeWidthAttributeName;(边线宽度)
</span></span></span><span class="line"><span class="cl"><span class="cm"> NSString *const NSShadowAttributeName;(阴影)(横竖排版 
</span></span></span><span class="line"><span class="cl"><span class="cm"> NSString *const NSVerticalGlyphFormAttributeName;
</span></span></span></code></pre></td></tr></table>
</div>
</div><h4 id="常量">常量</h4>
<blockquote>
<p>NSFontAttributeName(字体)</p>
</blockquote>
<p>该属性所对应的值是一个 UIFont 对象。该属性用于改变一段文本的字体。如果不指定该属性，则默认为12-point Helvetica(Neue)。</p>
<blockquote>
<p>NSParagraphStyleAttributeName(段落)</p>
</blockquote>
<p>该属性所对应的值是一个 NSParagraphStyle 对象。该属性在一段文本上应用多个属性。如果不指定该属性，则默认为 NSParagraphStyle 的defaultParagraphStyle 方法返回的默认段落属性。</p>
<blockquote>
<p>NSForegroundColorAttributeName(字体颜色)</p>
</blockquote>
<p>该属性所对应的值是一个 UIColor 对象。该属性用于指定一段文本的字体颜色。如果不指定该属性，则默认为黑色。</p>
<blockquote>
<p>NSBackgroundColorAttributeName(字体背景色)</p>
</blockquote>
<p>该属性所对应的值是一个 UIColor 对象。该属性用于指定一段文本的背景颜色。如果不指定该属性，则默认无背景色。</p>
<blockquote>
<p>NSLigatureAttributeName(连字符)</p>
</blockquote>
<p>该属性所对应的值是一个 NSNumber 对象(整数)。连体字符是指某些连在一起的字符，它们采用单个的图元符号。0 表示没有连体字符。1 表示使用默认的连体字符。2表示使用所有连体符号。默认值为 1（注意，iOS 不支持值为 2）。</p>
<blockquote>
<p>NSKernAttributeName(字间距)</p>
</blockquote>
<p>该属性所对应的值是一个 NSNumber 对象(整数)。字母紧排指定了用于调整字距的像素点数。字母紧排的效果依赖于字体。值为 0 表示不使用字母紧排。默认值为0。</p>
<blockquote>
<p>NSStrikethroughStyleAttributeName(删除线)</p>
</blockquote>
<p>该属性所对应的值是一个 NSNumber 对象(整数)。该值指定是否在文字上加上删除线，该值参考“Underline Style Attributes”。默认值是NSUnderlineStyleNone。</p>
<blockquote>
<p>NSUnderlineStyleAttributeName(下划线)</p>
</blockquote>
<p>该属性所对应的值是一个 NSNumber 对象(整数)。该值指定是否在文字上加上下划线，该值参考“Underline Style Attributes”。默认值是NSUnderlineStyleNone。</p>
<blockquote>
<p>NSStrokeColorAttributeName(边线颜色)</p>
</blockquote>
<p>该属性所对应的值是一个 UIColor 对象。如果该属性不指定（默认），则等同于 NSForegroundColorAttributeName。否则，指定为删除线或下划线颜色。更多细节见“Drawing attributedstrings that are both filled and stroked”。</p>
<blockquote>
<p>NSStrokeWidthAttributeName(边线宽度)</p>
</blockquote>
<p>该属性所对应的值是一个 NSNumber 对象(小数)。该值改变描边宽度（相对于字体size 的百分比）。默认为 0，即不改变。正数只改变描边宽度。负数同时改变文字的描边和填充宽度。例如，对于常见的空心字，这个值通常为3.0。</p>
<blockquote>
<p>NSShadowAttributeName(阴影)</p>
</blockquote>
<p>该属性所对应的值是一个 NSShadow 对象。默认为 nil。</p>
<blockquote>
<p>NSVerticalGlyphFormAttributeName(横竖排版)</p>
</blockquote>
<p>该属性所对应的值是一个 NSNumber 对象(整数)。0 表示横排文本。1 表示竖排文本。在 iOS 中，总是使用横排文本，0 以外的值都未定义。</p>
    </div>

    <div class="post-copyright">
  <p class="copyright-item">
    <span class="item-title">文章作者</span>
    <span class="item-content">Rango</span>
  </p>
  <p class="copyright-item">
    <span class="item-title">上次更新</span>
    <span class="item-content">
        2016-04-27
        
    </span>
  </p>
  
  
</div>
<div class="post-reward">
  <input type="checkbox" name="reward" id="reward" hidden />
  <label class="reward-button" for="reward">赞赏支持</label>
  <div class="qr-code">
    
    <label class="qr-code-image" for="reward">
        <img class="image" src="/img/reward/wechat.jpg">
        <span>微信打赏</span>
      </label>
    <label class="qr-code-image" for="reward">
        <img class="image" src="/img/reward/alipay.jpg">
        <span>支付宝打赏</span>
      </label>
  </div>
</div><footer class="post-footer">
      <div class="post-tags">
          <a href="/tags/oc/">OC</a>
          <a href="/tags/nsattributedstring/">NSAttributedString</a>
          </div>
      <nav class="post-nav">
        <a class="prev" href="/post/others/front-matter/">
            <i class="iconfont icon-left"></i>
            <span class="prev-text nav-default">Github上的 MarkDown 前页格式</span>
            <span class="prev-text nav-mobile">上一篇</span>
          </a>
        <a class="next" href="/post/assembly/%E6%B1%87%E7%BC%96%E4%B8%AD%E7%9A%84bssdatatext%E7%AD%89/">
            <span class="next-text nav-default">汇编中的bss、data、text、rodata、heap、stack的意义？</span>
            <span class="next-text nav-mobile">下一篇</span>
            <i class="iconfont icon-right"></i>
          </a>
      </nav>
    </footer>
  </article>
        </div>
        

  

  

      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="social-links">
      <a href="mailto:rangodev@163.com" class="iconfont icon-email" title="email"></a>
  <a href="https://rangolee.github.io/index.xml" type="application/rss+xml" class="iconfont icon-rss" title="rss"></a>
</div>

<div class="copyright">
  <span class="power-by">
    由 <a class="hexo-link" href="https://gohugo.io">Hugo</a> 强力驱动
  </span>
  <span class="division">|</span>
  <span class="theme-info">
    主题 - 
    <a class="theme-link" href="https://github.com/olOwOlo/hugo-theme-even">Even</a>
  </span>

  

  <span class="copyright-year">
    &copy; 
    2016 - 
    2022<span class="heart"><i class="iconfont icon-heart"></i></span><span>Rango</span>
  </span>
</div>

    </footer>

    <div class="back-to-top" id="back-to-top">
      <i class="iconfont icon-up"></i>
    </div>
  </div>
  
  <script src="https://cdn.jsdelivr.net/npm/jquery@3.2.1/dist/jquery.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/slideout@1.0.1/dist/slideout.min.js" integrity="sha256-t+zJ/g8/KXIJMjSVQdnibt4dlaDxc9zXr/9oNPeWqdg=" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.1.20/dist/jquery.fancybox.min.js" integrity="sha256-XVLffZaxoWfGUEbdzuLi7pwaUJv1cecsQJQqGLe7axY=" crossorigin="anonymous"></script>



<script type="text/javascript" src="/js/main.min.64437849d125a2d603b3e71d6de5225d641a32d17168a58106e0b61852079683.js"></script>








</body>
</html>
